<?php

namespace App\Services\Admin;

use App\Models\UserIntegral as UserIntegralModel;
use App\Models\Vip as VipModel;
use App\Models\User as UserModel;
use App\Services\Api\UserIntegralServices;

class UserIntegral extends Base
{
    public static function lists()
    {

        $input = request()->all();

        $where = [];

        if (!empty($input['user_id'])) $where[] = ['user_id', $input['user_id']];
        if (!empty($input['status'])) $where[] = ['status', 'like', '%' . $input['status'] . '%'];
        if (!empty($input['start_time']) && !empty($input['end_time'])){
            $where[] = ['created_at','>=',"{$input['start_time']} 00:00:00"];
            $where[] = ['created_at','<=',"{$input['end_time']} 23:59:59"];
        }

        return (new UserIntegralModel)->with(['user','integral_plan','pay_type'])->where($where)->orderBy('id','desc')->paginate(6);

    }

    public static function vip_lists()
    {
        $input = request()->all();

        $where = [];

        if (!empty($input['id'])) $where[] = ['id', $input['id']];

        return (new VipModel)->with(['vip_info'])->where($where)->orderBy('id','desc')->get();
    }

    public static function info($id)
    {
        return (new UserIntegralModel)->with([
            'user','integral_plan','pay_type', 'user_vip'
        ])->where('id', $id)->first();
    }

    public static function add($param = [])
    {
        //return (new UserIntegralModel)->insert($param);
    }

    public static function edit($id , $param=[])
    {
        //UserModel::where('id',$param['user_id'])->increment('total_integral',$param['integral']);
       // if(empty()){

        //}
        $services = new UserIntegralServices();
        return $services->add_integral($id, $param);
        //return (new UserIntegralModel)->where('id',$id)->update($param);
    }



}
